package com.cpr.demo.mycraft.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

/**
 * @author Chen Panrui
 * created at 2021/9/16 15:19
 */
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		BeanDefinition msBeanDef = beanFactory.getBeanDefinition(MyConstant.MY_SERVICE);
		MutablePropertyValues propertyValues = msBeanDef.getPropertyValues();
		propertyValues.addPropertyValue(new PropertyValue("roomNo","T_256"));
		System.out.println("---房间号T_256");
		msBeanDef.setLazyInit(true);
		/*
		 * 此时只是重新定义了 BeanDefinition，bean的初始化还没有发生
		 */
	}

}
